var express = require('express');
var router = express.Router();

/* GET users listing. */
router.get('/', function (req, res, next) {
    let cookie = req.headers.cookie;
    console.log(cookie + ' login的cookie');
    if (cookie && /username/.test(cookie)) {
        res.redirect(301, '/');
        // res.end();
    } else {
        res.render('login', {
            title: 'xiao7'
        });
    }
});
router.post('/', function (req, res) {
    console.log(req.body);
    // console.log(req);
    res.cookie('username', req.body.username, {
        domain: '.liuwenxi.me',//cookie不支持跨域
        maxAge: 10*60*1000
    }).json({
        err: 0
    });
})

module.exports = router;
